﻿
using System.Configuration;
using System.Reflection;

namespace OnlineBookStore.DALFactory
{
    /// <summary>
    /// 数据访问类，通过抽象工厂的模式从配置文件中创建数据访问层的实例
    /// </summary>
    public sealed class DataAccess
    {
        /// <summary>
        /// 通过反射，查找数据访问层实例的路径
        /// </summary>
        private static readonly string path = ConfigurationManager.AppSettings["WebDAL"];//需要添加System.configuration的引用
        /// <summary>
        /// 这个类不需要创建实例，所以将构造函数设为私有
        /// </summary>
        private DataAccess() { }

        public static OnlineBookStore.IDAL.IUser CreateUser() {
            string className = path + ".User";
            return (OnlineBookStore.IDAL.IUser)Assembly.Load(path).CreateInstance(className);
        }

    }
}
